import { http } from "@/utils/http";
import type { ResultTable } from "@/api/type";

interface FormItemProps {
  id?: string;
  chapterId?: number | string;
  uid?: number | string;
  content?: string;
  level?: number;
  parentId?: number | string;
  likes?: number;
  username?: string;
  homeLink?: string;
  address?: string;
  avatar?: string;
  contentImg?: string;
  createdAt?: Date | string;
  reply?: {
    total?: number;
    list?: FormItemProps[];
  };
}

interface Result {
  code?: number;
  msg?: string;
  data?: FormItemProps;
}

interface Res<T> {
  code?: number;
  msg?: string;
  data?: T;
}

const modulePath = "/learn/comments";

/** 评论列表 */
export const getCommentsList = (params?: object) => {
  return http.request<ResultTable>("get", modulePath + "/list", {
    params
  });
};
/** 章节的评论 */
export const getChapterById = (params?: object) => {
  return http.request<Res<FormItemProps[]>>(
    "get",
    modulePath + "/getChapterById",
    {
      params
    }
  );
};

/** 新增 */
export const commentsAdd = (data?: FormItemProps) => {
  return http.request<Result>("post", modulePath + "/add", { data });
};

/** 修改 */
export const commentsUpdate = (data?: FormItemProps) => {
  return http.request<Result>("put", modulePath + "/update", {
    data
  });
};

/** 删除 */
export const commentsDel = (data: object) => {
  return http.request<Result>("delete", modulePath + "/delete", {
    data
  });
};
